﻿using Ideaa.Data.Infrastructure;
using Ideaa.Data.Models;
using Ideaa.Services.Base;
using Ideaa.Services.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ideaa.Services.Services
{
    public class VoteService : BaseService, IVoteService
    {
        public VoteService(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
        }

        public void Add(Vote vote)
        {
            if (vote == null)
            {
                throw new NullReferenceException("Vote could not be found.");
            }

            this.unitOfWork.Votes.Add(vote);
        }

        public void Remove(Vote vote)
        {
            if (vote == null)
            {
                throw new NullReferenceException("Vote could not be found.");
            }

            this.unitOfWork.Votes.Delete(vote);
        }

        public IList<Vote> GetVotesBySuggestionId(int suggestionId)
        {
            if (suggestionId == null || suggestionId < 1)
            {
                throw new NullReferenceException("Suggestion not found;");
            }

            return this.unitOfWork.Votes.All().Where(x => x.SuggestionId == suggestionId).ToList();
        }
    }
}
